文章目录
  1. Oozie-7_Java API
  2. 1. 一个简单的例子
  3. 2. 获取任务详情 (Junit 测试)

Oozie-7_Java API

1. 一个简单的例子

  • 依赖包
1
2
3
4
5
<dependency>
<groupId>org.apache.oozie</groupId>
<artifactId>oozie-client</artifactId>
<version>4.1.0</version>
</dependency>
  • java 代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
public class WordCountTest {

public static void main(String[] args) throws OozieClientException, InterruptedException {

// 获取 Oozie Client
OozieClient client = new OozieClient("http://127.0.0.1:11000/oozie");

// 设置配置
Properties configuration = client.createConfiguration();
configuration.put(OozieClient.APP_PATH, "hdfs://127.0.0.1:9000/user/icemimosa/examples/apps/map-reduce/workflow.xml");
configuration.put("nameNode", "hdfs://127.0.0.1:9000");
configuration.put("jobTracker", "localhost:8032");
configuration.put("queueName", "default");
configuration.put("examplesRoot", "examples");
configuration.put("outputDir", "map-reduce");

// 执行
String jobId = client.run(configuration);
while(client.getJobInfo(jobId).getStatus() == WorkflowJob.Status.RUNNING) {
System.out.println("Workflow job running ...");
Thread.sleep(5 * 1000);
}

// 执行结束
System.out.println("Workflow job completed ...");
System.out.println(client.getJobInfo(jobId));
}
}

2. 获取任务详情 (Junit 测试)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
package io.terminus.oozie;

import org.apache.oozie.client.CoordinatorAction;
import org.apache.oozie.client.CoordinatorJob;
import org.apache.oozie.client.OozieClientException;
import org.apache.oozie.client.WorkflowAction;
import org.apache.oozie.client.WorkflowJob;
import org.apache.oozie.client.XOozieClient;
import org.junit.Before;
import org.junit.Test;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;

/**
* Desc: Oozie client Test
* Mail: chk@terminus.io
* Created by IceMimosa
* Date: 16/7/31
*/
public class OozieClientTest {

private XOozieClient client;

@Before
public void before() throws OozieClientException {
client = new XOozieClient("http://127.0.0.1:11000/oozie");
// Map<String, String> configuration = client.getServerConfiguration();
// System.out.println(configuration.get("oozie.service.WorkflowAppService.system.libpath"));
}


/**
* 测试workflow详情
* @throws OozieClientException
*/
@Test
public void test_WorkflowJobs() throws OozieClientException {
WorkflowJob workflowJob = client.getJobInfo("0000000-160704142405284-oozie-icem-W");

System.out.println("---------------------- Workflow job ------------------------");

// 遍历 workflowJob
print("[Workflow Job id]", workflowJob.getId());
print("[Workflow Job appName]", workflowJob.getAppName());
print("[Workflow Job appPath]", workflowJob.getAppPath());
print("[Workflow Job conf]", workflowJob.getConf());
print("[Workflow Job console url]", workflowJob.getConsoleUrl());
print("[Workflow Job status]", workflowJob.getStatus());
print("[Workflow Job parent id]", workflowJob.getParentId());
print("[Workflow Job external id]", workflowJob.getExternalId());
print("[Workflow Job user]", workflowJob.getUser());
print("[Workflow Job group]", workflowJob.getGroup());
print("[Workflow Job acl]", workflowJob.getAcl());
print("[Workflow Job run]", workflowJob.getRun());
print("[Workflow Job create time]", workflowJob.getCreatedTime());
print("[Workflow Job start time]", workflowJob.getStartTime());
print("[Workflow Job end time]", workflowJob.getEndTime());
print("[Workflow Job last modify time]", workflowJob.getLastModifiedTime());

// workflowJob.getActions().forEach(this::printAction);
}

private void printAction(WorkflowAction action) {
System.out.println();
System.out.println("---------------------- Workflow job Action ------------------------");

print("[WF Action id]", action.getId());
print("[WF Action name]", action.getName());
// print("[WF Action cred]", action.getCred());
print("[WF Action type]", action.getType());
print("[WF Action conf]", action.getConf());
print("[WF Action tracker uri]", action.getTrackerUri());
print("[WF Action console url]", action.getConsoleUrl());
print("[WF Action status]", action.getStatus());
print("[WF Action statistic]", action.getStats());
print("[WF Action data]", action.getData());
print("[WF Action external id]", action.getExternalId());
print("[WF Action external child ids]", action.getExternalChildIDs());
print("[WF Action external status]", action.getExternalStatus());
print("[WF Action error code]", action.getErrorCode());
print("[WF Action error message]", action.getErrorMessage());

print("[WF Action start time]", action.getStartTime());
print("[WF Action end time]", action.getEndTime());
print("[WF Action transition]", action.getTransition());

// print("[WF Action retries]", action.getRetries());
// print("[WF Action RetryCount]", action.getUserRetryCount());
// print("[WF Action RetryInterval]", action.getUserRetryInterval());
// print("[WF Action RetryMax]", action.getUserRetryMax());

}


/**
* 测试Coordinator详情
* @throws OozieClientException
*/
@Test
public void test_CoordinatorJobs() throws OozieClientException {
CoordinatorJob coordJobInfo = client.getCoordJobInfo("0000006-160922094314569-oozie-icem-C");

System.out.println("---------------------- Workflow job ------------------------");

print("[Coordinator Job id]", coordJobInfo.getId());
print("[Coordinator app name]", coordJobInfo.getAppName());
print("[Coordinator app path]", coordJobInfo.getAppPath());
print("[Coordinator status]", coordJobInfo.getStatus());
print("[Coordinator ExternalId]", coordJobInfo.getExternalId());
print("[Coordinator bundle id]", coordJobInfo.getBundleId());
print("[Coordinator Concurrency]", coordJobInfo.getConcurrency());
print("[Coordinator Conf]", coordJobInfo.getConf());
print("[Coordinator user]", coordJobInfo.getUser());
print("[Coordinator acl]", coordJobInfo.getAcl());
print("[Coordinator group]", coordJobInfo.getGroup());
print("[Coordinator ConsoleUrl]", coordJobInfo.getConsoleUrl());
print("[Coordinator Frequency]", coordJobInfo.getFrequency());
print("[Coordinator ExecutionOrder]", coordJobInfo.getExecutionOrder());

print("[Coordinator start time]", coordJobInfo.getStartTime());
print("[Coordinator end time]", coordJobInfo.getEndTime());
print("[Coordinator pause time]", coordJobInfo.getPauseTime());
print("[Coordinator NextMaterializedTime]", coordJobInfo.getNextMaterializedTime());
print("[Coordinator LastActionTime]", coordJobInfo.getLastActionTime());


print("[Coordinator TimeUnit]", coordJobInfo.getTimeUnit());
print("[Coordinator TimeZone]", coordJobInfo.getTimeZone());
print("[Coordinator Timeout]", coordJobInfo.getTimeout());

coordJobInfo.getActions().forEach(this::printCoordAction);
}

private void printCoordAction(CoordinatorAction action) {
System.out.println();
System.out.println("---------------------- Coordinator job Action ------------------------");

print("COORD Action id", action.getId());
print("COORD Action coordinator job id", action.getJobId());
print("COORD Action status", action.getStatus());
print("COORD Action ActionNumber", action.getActionNumber());
print("COORD Action ConsoleUrl", action.getConsoleUrl());
print("COORD Action TrackerUri", action.getTrackerUri());
print("COORD Action CreatedConf", action.getCreatedConf());
print("COORD Action RunConf", action.getRunConf());

print("COORD Action ExternalId", action.getExternalId());
print("COORD Action ExternalStatus", action.getExternalStatus());

print("COORD Action CreatedTime", action.getCreatedTime());
print("COORD Action NominalTime", action.getNominalTime());
print("COORD Action LastModifiedTime", action.getLastModifiedTime());
print("COORD Action MissingDependencies", action.getMissingDependencies());
print("COORD Action PushMissingDependencies", action.getPushMissingDependencies());

print("COORD Action ErrorCode", action.getErrorCode());
print("COORD Action ErrorMessage", action.getErrorMessage());
}

@Test
public void test_getWF_by_Coordinator() throws OozieClientException {

/// List<WorkflowJob> wfsForCoordAction = client.getWfsForCoordAction("0000000-160814191812274-oozie-icem-C@1");
}

/**
* 其他
* 1. 日志
* @throws OozieClientException
*/
@Test
public void test_Other() throws OozieClientException {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
client.getJobLog("0000090-160822184432088-oozie-admi-C", null, null, "loglevel=WARN;recent=168h", new PrintStream(buffer));
System.out.println(buffer.toString());
}


private void print(String message, Object value) {
System.out.println(message + " -----> " + value);
}
}
文章目录
  1. Oozie-7_Java API
  2. 1. 一个简单的例子
  3. 2. 获取任务详情 (Junit 测试)